#include "Instance.h"

ostream &operator<<(ostream& aOut, const Instance& aInstance) {
  aOut << aInstance.pNumber;
  for (unsigned int i = 0; i < aInstance.pBitSet.size(); ++i) {
    if (i % aInstance.pNumber == 0) aOut << endl;
    aOut << aInstance.pBitSet[i];
  }
  return aOut << endl;
}

istream &operator>>(istream& aIn, Instance& aInstance) {
  aIn >> aInstance.pNumber;
  aInstance.pBitSet.resize(aInstance.pNumber * aInstance.pNumber);
  uint16_t kRegularity = 0;
  for (unsigned int i=0; i < aInstance.pBitSet.size(); ++i) {
    char c;
    aIn >> c;
    kRegularity += (aInstance.pBitSet[i] = c == '0' ? false : true);
    //0..99(9999) == 100-1
    /*if (i+1 == aInstance.pNumber) {
      aInstance.pRegularity = kRegularity;
      kRegularity = 0;
    } else*/
    if ((i+1) % aInstance.pNumber == 0) {
      if (kRegularity > aInstance.pRegularity) aInstance.pRegularity = kRegularity;
      //if (aInstance.pRegularity != kRegularity) throw "Instance is not regular graph";
      kRegularity = 0;
    }
  }
  return aIn;
}


// vim: ts=2 fdm=marker syntax=cpp expandtab sw=2
